package com.yjm.test.Spring5.ch4.resource;

import java.io.File;
import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

public class ResourceDemo {
	private static void displayInfo(Resource res) throws IOException {
		System.out.println(res.getClass());
		System.out.println(res.getURI());
		System.out.println(res.getURL());
		System.out.println("\n");
	}
	public static void main(String[] args) throws IOException {
		ApplicationContext ctx = new ClassPathXmlApplicationContext();

		File file = File.createTempFile("test", ".txt");
		file.deleteOnExit();
		
		Resource res1 = ctx.getResource("file://" + file.getPath());
		displayInfo(res1);
		
		Resource res2 = ctx.getResource("classpath:labels_en.properties");
		displayInfo(res2);
		
		Resource res3 = ctx.getResource("http://www.baidu.com");
		displayInfo(res3);
	}

}
